
clear all
set more off, perm
capture log close
set maxvar 32767
global klmChinaReach2: env klmChinaReach2
global datapath "${klmChinaReach2}/Fuyao_Erlfang"
	
**# cognitive
cd "$datapath\estimates\maturation\Graphs\c"

use c_add, clear
// replace var_ub_ = add_pe + 1.96*var_sd_
// replace var_lb_ = add_pe - 1.96*var_sd_

// replace var1 = subinstr(var1, "Level ", "", .)
// destring var1, replace
// rename level levelc2 
*kbar
preserve 
keep if var == "Kbar"
label var var_ub_ "95% CI"
label var add_pe "Minimum Skill Requirement"
twoway scatter add_pe level, sort msize(medium) ||  rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium) ///
	xlabel(1(1)13, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Kbar, size(small)) ylabel(,labsize(small)) ///
	title("Minimum Latent Cognitive Skills Requirement by Level", size(medium)) subtitle(Additive Model w/ Scale Invariance, size(small)) legend(order(1 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
		note("Note: The confidence interval is based on 1,000 iteration bootstrap.", size(small) span)   ///
graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_kbar", replace)
	graph export "add_kbar.pdf", replace
restore


preserve 
keep if var != "Kbar" & var != "Delta"
label var var_ub_ "95% CI"
label var add_pe "{&sigma}{sup:2}({&epsilon},l)"
// foreach i in mul_pe var_lb_ var_ub_{
// 	replace `i' = ln(`i')
// }
replace var_lb_ = . if add_pe > 30
replace var_ub_ = . if add_pe > 30
replace add_pe = . if add_pe > 30

twoway scatter add_pe level, sort lwidth(medium) msize(medium) cmissing(n) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium) cmissing(n)  ///
	xlabel(2(1)12, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&sigma}{sup:2}({&epsilon},l)", size(small)) ylabel(,labsize(small)) ///
	title("Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Cognitive)", size(medium)) subtitle(Additive Model w/ Scale Invariance, size(small)) legend(order(1 "{&sigma}{sup:2}({&epsilon},l)" 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "The variances with values over 30 are dropped in the figure to better visualize the estimates" "and their confidence intervals are not shown." "Variances at level 1 and 13 are normalized to one", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_sigma_30", replace)
	graph export "add_sigma_30.pdf", replace	
restore	
	
	
**log version
preserve 
keep if var != "Kbar" & var != "Delta"
label var var_ub_ "95% CI"
label var add_pe "{&sigma}{sup:2}({&epsilon},l)"
foreach i in add_pe var_lb_ var_ub_{
	replace `i' = ln(`i')
}
// replace var_lb_ = . if mul_pe > 30
// replace var_ub_ = . if mul_pe > 30
// replace mul_pe = . if mul_pe > 30

twoway scatter add_pe level, sort lwidth(medium) msize(medium) cmissing(n) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium) cmissing(n)  ///
	xlabel(2(1)12, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&sigma}{sup:2}({&epsilon},l)", size(small)) ylabel(,labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("log({&sigma}{sup:2}({&epsilon},l))", size(small)) ylabel(,labsize(small)) ///
	title("Log of Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Cognitive)", size(medium)) subtitle(Additive Model w/ Scale Invariance, size(small)) legend(order(1 "{&sigma}{sup:2}({&epsilon},l)" 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Log values are shown in the figure to better visualize values of all levels." "Variances at Level 1 and 13 variances normalized to one.", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_sigma", replace)
	graph export "add_sigma.pdf", replace	
restore	
	
preserve 
keep if var == "Delta"
label var var_ub_ "95% CI"
label var add_pe "{&Delta}{sub:k}"
twoway scatter add_pe level, sort lwidth(medium) msize(medium) ||  rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium)  ///
	xlabel(2 5 6 7 8 10 11 12, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&Delta}{sub:k}", size(small)) ylabel(,labsize(small)) ///
	title("Learning Task Component ({&Delta}{sub:k}) by Level (Cognitive)", size(medium)) subtitle(Additive Model w/ Scale Invariance, size(small)) legend(order(1 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Values at Levels 1, 3, 4, 9 and 13 are normalized to 1.", size(small) span)   ///
graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_Delta", replace)
	graph export "add_Delta.pdf", replace	
restore	



**# cog_add_wo


	
use "c_add_wo_si", clear

capture destring var_lb_ var_ub_ var_sd_ , replace force
// replace var_ub_ = add_pe + 1.96*var_sd_
// replace var_lb_ = add_pe - 1.96*var_sd_

preserve 
keep if var == "Kbar"
label var var_ub_ "95% CI"
label var add_pe "Minimum Skill Requirement"
twoway scatter add_pe level, sort msize(medium) ||  rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium) ///
	xlabel(1(1)13, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Kbar, size(small)) ylabel(,labsize(small)) ///
	title("Minimum Latent Cognitive Skills Requirement by Level", size(medium)) subtitle(Additive Model w/ Scale Invariance, size(small)) legend(order(1 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
		note("Note: The confidence interval is based on 1,000 iteration bootstrap.", size(small) span)   ///
graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_kbar", replace)
	graph export "add_kbar_wo.pdf", replace
restore


preserve 
keep if var != "Kbar" & var != "Delta"& var != "Beta1"
label var var_ub_ "95% CI"
label var add_pe "{&sigma}{sup:2}({&epsilon},l)"
// foreach i in mul_pe var_lb_ var_ub_{
// 	replace `i' = ln(`i')
// }
replace var_lb_ = . if add_pe > 30
replace var_ub_ = . if add_pe > 30
replace add_pe = . if add_pe > 30

twoway scatter add_pe level, sort lwidth(medium) msize(medium) cmissing(n) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium) cmissing(n)  ///
	xlabel(2(1)12, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&sigma}{sup:2}({&epsilon},l)", size(small)) ylabel(,labsize(small)) ///
	title("Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Cognitive)", size(medium)) subtitle(Additive Model w/ Scale Invariance, size(small)) legend(order(1 "{&sigma}{sup:2}({&epsilon},l)" 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "The variances with values over 30 are dropped in the figure to better visualize the estimates" "and their confidence intervals are not shown." "Variances at level 1 and 13 are normalized to one", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_sigma_30_wo", replace)
	graph export "add_sigma_30_wo.pdf", replace	
restore	
	
	
**log version
preserve 
keep if var != "Kbar" & var != "Delta"& var != "Beta1"
label var var_ub_ "95% CI"
label var add_pe "{&sigma}{sup:2}({&epsilon},l)"
foreach i in add_pe var_lb_ var_ub_{
	replace `i' = ln(`i')
}

twoway scatter add_pe level, sort lwidth(medium) msize(medium) cmissing(n) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium) cmissing(n)  ///
	xlabel(2(1)12, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&sigma}{sup:2}({&epsilon},l)", size(small)) ylabel(,labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("log({&sigma}{sup:2}({&epsilon},l))", size(small)) ylabel(,labsize(small)) ///
	title("Log of Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Cognitive)", size(medium)) subtitle(Additive Model w/ Scale Invariance, size(small)) legend(order(1 "{&sigma}{sup:2}({&epsilon},l)" 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Log values are shown in the figure to better visualize values of all levels." "Variances at Level 1 and 13 variances normalized to one.", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_sigma_wo", replace)
	graph export "add_sigma_wo.pdf", replace	
restore	
	
preserve 
keep if var == "Delta"
label var var_ub_ "95% CI"
label var add_pe "{&Delta}{sub:k}"
twoway scatter add_pe level, sort lwidth(medium) msize(medium) ||  rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium)  ///
	xlabel(2 5 6 7 8 10 11 12, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&Delta}{sub:k}", size(small)) ylabel(,labsize(small)) ///
	title("Learning Task Component ({&Delta}{sub:k}) by Level (Cognitive)", size(medium)) subtitle(Additive Model w/ Scale Invariance, size(small)) legend(order(1 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Values at Levels 1, 3, 4, 9 and 13 are normalized to 1.", size(small) span)   ///
graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_Delta_wo", replace)
	graph export "add_Delta_wo.pdf", replace	
restore	



preserve 
keep if var == "Beta1"
label var var_ub_ "95% CI"
label var add_pe "{&beta}{sub:1}"
twoway connected add_pe level, sort lwidth(medium) msize(medium) || line var_ub_ level, sort lcolor(gs11) lpattern(dash) lwidth(medium) || line var_lb_ level, sort lcolor(gs11) lpattern(dash) lwidth(medium)   ///
	xlabel(1(1)13, labsize(small)) xmtick(, labsize(small)) yline(1, lcolor(khaki) lwidth(medium))  ///
	xtitle(Difficulty Level, size(small)) ytitle("{&beta}{sub:1}", size(small)) ylabel(,labsize(small)) ///
	title("Transformation Function Slope ({&beta}{sub:1}) by Level (Cognitive)", size(large)) subtitle(Additive Model w/o Scale Invariance, size(medium)) legend(order(1 2) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap.", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_beta1", replace)
	graph export "add_beta1.pdf", replace
restore	

	

**mul
**# cog_ mul

use "c_mul", clear
// replace var_ub_ = mul_pe + 1.96*var_sd_
// replace var_lb_ = mul_pe - 1.96*var_sd_

// replace var1 = subinstr(var1, "Level ", "", .)
// destring var1, replace
// rename level levelc2 
*kbar
preserve 
keep if var == "Kbar"
drop if level == 13
label var var_ub_ "95% CI"
label var mul_pe "Minimum Skill Requirement"
twoway scatter mul_pe level, sort lwidth(medium) msize(medium) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium)  ///
	xlabel(2(1)12, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Kbar, size(small)) ylabel(,labsize(small)) ///
	title("Minimum Latent Cognitive Skills Requirement by Level", size(medium)) subtitle(Multiplicative Model w/ Scale Invariance, size(small)) legend(order(1 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "The Value at Level 13 is dropped in this figure due to the extreme variance in the estimation." "The value at Level 1 normalized to one.", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("mul_kbar", replace)
	graph export "mul_kbar.pdf", replace
restore


preserve 
keep if var != "Kbar" & var != "Delta"
label var var_ub_ "95% CI"
label var mul_pe "{&sigma}{sup:2}({&epsilon},l)"
// foreach i in mul_pe var_lb_ var_ub_{
// 	replace `i' = ln(`i')
// }
replace var_lb_ = . if mul_pe > 30
replace var_ub_ = . if mul_pe > 30
replace mul_pe = . if mul_pe > 30

twoway scatter mul_pe level, sort lwidth(medium) msize(medium) cmissing(n) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium) cmissing(n)  ///
	xlabel(2(1)12, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&sigma}{sup:2}({&epsilon},l)", size(small)) ylabel(,labsize(small)) ///
	title("Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Cognitive)", size(medium)) subtitle(Multiplicative Model w/ Scale Invariance, size(small)) legend(order(1 "{&sigma}{sup:2}({&epsilon},l)" 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "The variances with values over 30 are dropped in the figure to better visualize the estimates" "and their confidence intervals are not shown." "Variances at level 1 and 13 are normalized to one", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("mul_sigma_30", replace)
	graph export "mul_sigma_30.pdf", replace	
restore	
	
	
**log version
preserve 
keep if var != "Kbar" & var != "Delta"
label var var_ub_ "95% CI"
label var mul_pe "{&sigma}{sup:2}({&epsilon},l)"
foreach i in mul_pe var_lb_ var_ub_{
	replace `i' = ln(`i')
}
// replace var_lb_ = . if mul_pe > 30
// replace var_ub_ = . if mul_pe > 30
// replace mul_pe = . if mul_pe > 30

twoway scatter mul_pe level, sort lwidth(medium) msize(medium) cmissing(n) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium) cmissing(n)  ///
	xlabel(2(1)12, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&sigma}{sup:2}({&epsilon},l)", size(small)) ylabel(,labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("log({&sigma}{sup:2}({&epsilon},l))", size(small)) ylabel(,labsize(small)) ///
	title("Log of Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Cognitive)", size(medium)) subtitle(Multiplicative Model w/ Scale Invariance, size(small)) legend(order(1 "{&sigma}{sup:2}({&epsilon},l)" 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Log values are shown in the figure to better visualize values of all levels" "Variances at Level 1 and 13 are normalized to one.", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("mul_sigma", replace)
	graph export "mul_sigma.pdf", replace	
restore	
	
//	
// preserve 
// keep if var == "Delta"
// label var var_ub_ "95% CI"
// label var mul_pe "{&Delta}{sub:k}"
// twoway scatter mul_pe level, sort lwidth(medium) msize(medium) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium)  ///
// 	xlabel(2 5 6 7 8 10 11 12, labsize(small)) xmtick(, labsize(small)) ///
// 	xtitle(Difficulty Level, size(small)) ytitle("{&Delta}{sub:k}", size(small)) ylabel(,labsize(small)) ///
// 	title("Learning Task Component ({&Delta}{sub:k}) by Level (Cognitive)", size(medium)) subtitle(Multiplicative Model w/ Scale Invariance, size(small)) legend(order(1 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
// 	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Levels 1, 3, 4, 9 and 13 normalized to 1.", size(small) span)   ///
// 	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
// 	saving("mul_Delta", replace)
// 	graph export "mul_Delta.pdf", replace	
// restore	

**# cog w/o invariance

use "c_mul_wo_si", clear
capture destring var_lb_ var_ub_, replace force

// replace var_ub_ = mul_pe + 1.96*var_sd_
// replace var_lb_ = mul_pe - 1.96*var_sd_

// replace var1 = subinstr(var1, "Level ", "", .)
// destring var1, replace
// rename level levelc2 
*kbar
preserve 
keep if var == "Kbar"
drop if level == 13
label var var_ub_ "95% CI"
label var mul_pe "Minimum Skill Requirement"
twoway scatter mul_pe level, sort lwidth(medium) msize(medium) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium)  ///
	xlabel(2(1)12, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Kbar, size(small)) ylabel(,labsize(small)) ///
	title("Minimum Latent Cognitive Skills Requirement by Level", size(medium)) subtitle(Multiplicative Model w/ Scale Invariance, size(small)) legend(order(1 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "The Value at Level 13 is dropped in this figure due to the extreme variance in the estimation." "The value at Level 1 normalized to one.", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("mul_kbar_wo", replace)
	graph export "mul_kbar_wo.pdf", replace
restore


preserve 
keep if var != "Kbar" & var != "Delta"& var != "Beta1"
label var var_ub_ "95% CI"
label var mul_pe "{&sigma}{sup:2}({&epsilon},l)"
// foreach i in mul_pe var_lb_ var_ub_{
// 	replace `i' = ln(`i')
// }
replace var_lb_ = . if mul_pe > 30
replace var_ub_ = . if mul_pe > 30
replace mul_pe = . if mul_pe > 30

twoway scatter mul_pe level, sort lwidth(medium) msize(medium) cmissing(n) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium) cmissing(n)  ///
	xlabel(2(1)12, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&sigma}{sup:2}({&epsilon},l)", size(small)) ylabel(,labsize(small)) ///
	title("Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Cognitive)", size(medium)) subtitle(Multiplicative Model w/ Scale Invariance, size(small)) legend(order(1 "{&sigma}{sup:2}({&epsilon},l)" 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "The variances with values over 30 are dropped in the figure to better visualize the estimates" "and their confidence intervals are not shown." "Variances at level 1 and 13 are normalized to one", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("mul_sigma_30_wo", replace)
	graph export "mul_sigma_30_wo.pdf", replace	
restore	
	
	
**log version
preserve 
keep if var != "Kbar" & var != "Delta"& var != "Beta1"
label var var_ub_ "95% CI"
label var mul_pe "{&sigma}{sup:2}({&epsilon},l)"
foreach i in mul_pe var_lb_ var_ub_{
	replace `i' = ln(`i')
}
// replace var_lb_ = . if mul_pe > 30
// replace var_ub_ = . if mul_pe > 30
// replace mul_pe = . if mul_pe > 30

twoway scatter mul_pe level, sort lwidth(medium) msize(medium) cmissing(n) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium) cmissing(n)  ///
	xlabel(2(1)12, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&sigma}{sup:2}({&epsilon},l)", size(small)) ylabel(,labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("log({&sigma}{sup:2}({&epsilon},l))", size(small)) ylabel(,labsize(small)) ///
	title("Log of Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Cognitive)", size(medium)) subtitle(Multiplicative Model w/ Scale Invariance, size(small)) legend(order(1 "{&sigma}{sup:2}({&epsilon},l)" 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Log values are shown in the figure to better visualize values of all levels" "Variances at Level 1 and 13 are normalized to one.", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("mul_sigma_wo", replace)
	graph export "mul_sigma_wo.pdf", replace	
restore	


preserve 
 replace var_ub_ = mul_pe + 1.96*var_sd_
 replace var_lb_ = mul_pe - 1.96*var_sd_

keep if var == "Beta1"
label var var_ub_ "95% CI"
label var mul_pe "{&gamma}{sub:1,l}"
twoway connected mul_pe level, sort lwidth(medium) msize(medium) || line var_ub_ level, sort lcolor(gs11) lpattern(dash) lwidth(medium) || line var_lb_ level, sort lcolor(gs11) lpattern(dash) lwidth(medium)   ///
	xlabel(1(1)13, labsize(small)) xmtick(, labsize(small)) yline(1, lcolor(khaki) lwidth(medium)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&gamma}{sub:1,l}", size(small)) ylabel(,labsize(small)) ///
	title("Transformation Function Slope ({&gamma}{sub:1,l}) by Level (Cognitive)", size(large)) subtitle(Multiplicative Model w/o Scale Invariance, size(medium)) legend(order(1 2) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on standard error.", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("mul_beta1_sd", replace)
	graph export "mul_beta1_sd.pdf", replace
restore	

	
**# cog_deltaeta

use eta_delta_c_add, clear
label var m_eta_1_ "Fast"
label var m_eta_2_ "Normal"
label var m_eta_3_ "Slow"
label var ul_1_ "95% CI"
// twoway line m_eta_1_ level, sort lwidth(medium) || line ul_1_ level, sort lcolor(gs15) lpattern(dash) lwidth(medium) || line ll_1_ level, sort lcolor(gs15) lpattern(dash) lwidth(medium) || connected m_eta_2_ level, sort msize(medium) lwidth(medium) || line ul_2_ level, sort lcolor(gs15) lpattern(dash) lwidth(medium) || line ll_2_ level, sort lcolor(gs15) lpattern(dash) lwidth(medium) || line m_eta_3_ level, sort lpattern(longdash_shortdash) lwidth(medium) || line ul_3_ level, sort lcolor(gs15) lpattern(dash) lwidth(medium) || line ll_3_ level, sort lcolor(gs15) lpattern(dash) lwidth(medium) ///
twoway connected m_eta_1_ level, sort lwidth(medthick) msize(medium) mc(navy) lcolor(navy) lpattern(dash)|| rcap ul_1_ ll_1_ level, sort lcolor(gs12) lwidth(medthick) || connected m_eta_2_ level, sort msize(medium) m(S) mc(olive) lcolor(olive)  lpattern(dash) || rcap ul_2_ ll_2_ level, sort lcolor(gs12) lwidth(medthick) || connected m_eta_3_ level, sort msize(medium) m(T) mc(orange) lcolor(orange)  lpattern(dash) || rcap ul_3_ ll_3_ level, sort lcolor(gs12) lwidth(medthick)  ///
	xlabel(2 5 6 7 8 10 11 12, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle({&delta}(l)E({&eta}), size(small)) ylabel(,labsize(small)) ///
	title(Learning Component ({&delta}(l)E({&eta})) by Difficulty Level (Cognitive), size(med)) subtitle(by Ability Group, size(medsmall)) legend(order(1 3 5 2 "95% CI") row(1) size(vsmall) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Fast group: the child can pass the first task at over 80% of the difficulty levels, and the average pass rate at that level is greater than 80%." "Normal group: the child doesn't pass the first task, and the pass rate is greater than 50%; or the child passes the first task, and the pass rate is" "between 50% and 80%. Slow group: the average pass rate is less than 50%.    2. 95% confidence intervals are shown for three groups." "3. The values of {&Delta} for level 1, 3, 4, 9, and 13 are normalized to one.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_deltaeta", replace)
	graph export "add_deltaeta.pdf", replace



	
use eta_delta_c_mul, clear
label var m_eta_1_ "Fast"
label var m_eta_2_ "Normal"
label var m_eta_3_ "Slow"
label var ul_1_ "95% CI"
// twoway line m_eta_1_ level, sort lwidth(medium) || line ul_1_ level, sort lcolor(gs15) lpattern(dash) lwidth(medium) || line ll_1_ level, sort lcolor(gs15) lpattern(dash) lwidth(medium) || connected m_eta_2_ level, sort msize(medium) lwidth(medium) || line ul_2_ level, sort lcolor(gs15) lpattern(dash) lwidth(medium) || line ll_2_ level, sort lcolor(gs15) lpattern(dash) lwidth(medium) || line m_eta_3_ level, sort lpattern(longdash_shortdash) lwidth(medium) || line ul_3_ level, sort lcolor(gs15) lpattern(dash) lwidth(medium) || line ll_3_ level, sort lcolor(gs15) lpattern(dash) lwidth(medium) ///

// twoway scatter m_eta_1_ level, sort lwidth(medthick) msize(medium) mc(navy) lcolor(navy) lpattern(dash)|| rcap ul_1_ ll_1_ level, sort lcolor(gs12) lwidth(medthick) || scatter m_eta_2_ level, sort msize(medium) m(S) mc(olive) lcolor(olive)  lpattern(dash) || rcap ul_2_ ll_2_ level, sort lcolor(gs12) lwidth(medthick) || scatter m_eta_3_ level, sort msize(medium) m(T) mc(orange) lcolor(orange)  lpattern(dash) || rcap ul_3_ ll_3_ level, sort lcolor(gs12) lwidth(medthick)  ///
twoway connected m_eta_1_ level, sort lwidth(medthick) msize(medium) mc(navy) lcolor(navy) lpattern(dash)|| rcap ul_1_ ll_1_ level, sort lcolor(gs12) lwidth(medthick) || connected m_eta_2_ level, sort msize(medium) m(S) mc(olive) lcolor(olive)  lpattern(dash) || rcap ul_2_ ll_2_ level, sort lcolor(gs12) lwidth(medthick) || connected m_eta_3_ level, sort msize(medium) m(T) mc(orange) lcolor(orange)  lpattern(dash) || rcap ul_3_ ll_3_ level, sort lcolor(gs12) lwidth(medthick)  ///	
	xlabel(2 5 6 7 8 10 11 12, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle({&delta}(l)E({&eta}), size(small)) ylabel(,labsize(small)) ///
	title(Learning Component ({&delta}(l)E({&eta})) by Difficulty Level (Cognitive), size(med)) subtitle(by Ability Group, size(medsmall)) legend(order(1 3 5 2 "95% CI") row(1) size(vsmall) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Fast group: the child can pass the first task at over 80% of the difficulty levels, and the average pass rate at that level is greater than 80%." "Normal group: the child doesn't pass the first task, and the pass rate is greater than 50%; or the child passes the first task, and the pass rate is" "between 50% and 80%. Slow group: the average pass rate is less than 50%.    2. 95% confidence intervals are shown for three groups." "3. The values of {&Delta} for level 1, 3, 4, 9, and 13 are normalized to one.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("mul_deltaeta", replace)
	graph export "mul_deltaeta.pdf", replace


/*


graph combine "add_sigma_30" "mul_sigma_30", rows(1) title("Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Fine Motor)", size(medlarge)) ///
	xsize(11) ysize(4) ycommon   ///
	graphregion(margin(small) fcolor(white) ifcolor(white)) plotregion(margin(small) fcolor(white))  ///
	saving("add_mul_sigma_30", replace)
	graph export "add_mul_sigma_30.pdf", replace
	

	
graph combine "add_beta0_no12" "mul_beta0", 	rows(1) title("Transformation Function {&omega}{sub:l} (Cognitive)", size(medlarge)) ///
	subtitle(Additive and Multiplicative Model Intercept ({&beta}{sub:0,l}), size(medium)) xsize(12) ysize(4) ycommon  ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Level 12 of Additive Model is dropped because the value is bigger than 10.", size(small) span)   ///
	graphregion(margin(small) fcolor(white) ifcolor(white)) plotregion(margin(small) fcolor(white))  ///
	saving("add_mul_beta0", replace)
	graph export "add_mul_beta0.pdf", replace
*/